package com.huitone.gddw.service.impl.system;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.huitone.gddw.dao.entity.SmLog;
import com.huitone.gddw.dao.system.ISmLogDao;
import com.huitone.gddw.model.support.QueryPage;
import com.huitone.gddw.service.dto.system.SmLogDTO;
import com.huitone.gddw.service.system.ISmLogService;
import com.huitone.gddw.utils.SysLoginUtil;

/**
 * 门户日志 接口实现类
 * @author wuluodan
 *
 */
@Service
public class SmLogService implements ISmLogService {

	@Autowired
	private ISmLogDao smLogDao;
	
	@Override
	public QueryPage<SmLogDTO> selectPage(QueryPage<SmLog> page) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("startDate", page.getParams().get("startDate"));
		map.put("endDate", page.getParams().get("endDate"));
		map.put("logType", page.getParams().get("logType"));
		map.put("userName", page.getParams().get("userName"));
		map.put("start", (page.getPageNo() - 1) * page.getPageSize() + 1);
		map.put("end", page.getPageNo() * page.getPageSize());
		List<SmLogDTO> result = smLogDao.selectPage(map);
		int totalCount = smLogDao.selectCount(map);
		
		QueryPage<SmLogDTO> queryPage = new QueryPage<SmLogDTO>();
		queryPage.setResult(result);
		queryPage.setPageNo(page.getPageNo());
		queryPage.setPageSize(page.getPageSize());
		queryPage.setTotalCount(totalCount);
		return queryPage;
	}

	@Override
	public void save(SmLog entity) {
		entity.setUserId(SysLoginUtil.getLoginUserId());
		entity.setLogTime(new Date());
		entity.setInsertTime(new Date());
		smLogDao.insertSelective(entity);
	}

}
